
package com.flowmodule.dao;
import com.flowmodule.bean.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import util.*;
public class TbFlowProcessDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbFlowProcess tbFlowProcess=null;
    private List<TbFlowProcess> tbFlowProcessList=null;

    public boolean add(TbFlowProcess inTbFlowProcess){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_FlowProcess(FlowId,FlowNodeId,UserId) values(?,?,?)";
        pt = conn.prepareStatement(sql);
        pt.setInt(1,inTbFlowProcess.getFlowId());
        pt.setInt(2,inTbFlowProcess.getFlowNodeId());
        pt.setInt(3,inTbFlowProcess.getUserId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inFlowProcessId){
        return UtilDAO.del("Tb_FlowProcess", "FlowProcessId", inFlowProcessId);
    }
    public boolean edit(TbFlowProcess inTbFlowProcess){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_FlowProcess set FlowId=?,FlowNodeId=?,UserId=?,CreateTime=getdate() where FlowProcessId=?";
        pt = conn.prepareStatement(sql);
        pt.setInt(1,inTbFlowProcess.getFlowId());
        pt.setInt(2,inTbFlowProcess.getFlowNodeId());
        pt.setInt(3,inTbFlowProcess.getUserId());
        pt.setInt(4,inTbFlowProcess.getFlowProcessId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbFlowProcess getTbFlowProcessByFlowProcessId(int inFlowProcessId) {
        tbFlowProcess=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowProcess where FlowProcessId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inFlowProcessId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbFlowProcess == null)tbFlowProcess = getTbFlowProcess(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowProcess;
    }
    public List<TbFlowProcess> getTbFlowProcessAll() {
        tbFlowProcessList=new ArrayList<TbFlowProcess>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowProcess";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowProcessList.add(getTbFlowProcess(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowProcessList;
    }
    public List<TbFlowProcess> getTbFlowProcessAll(VskPage vp) {
        tbFlowProcessList=new ArrayList<TbFlowProcess>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowProcess";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_FlowProcess", "FlowProcessId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowProcessList.add(getTbFlowProcess(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowProcessList;
    }
    public TbFlowProcess getTbFlowProcess(ResultSet rs) throws Exception{
        TbFlowProcess tbFlowProcess = new TbFlowProcess();
        tbFlowProcess.setFlowProcessId(rs.getInt("FlowProcessId"));
        tbFlowProcess.setFlowId(rs.getInt("FlowId"));
        tbFlowProcess.setFlowNodeId(rs.getInt("FlowNodeId"));
        tbFlowProcess.setUserId(rs.getInt("UserId"));
        tbFlowProcess.setCreateTime(rs.getString("CreateTime"));
        return tbFlowProcess;
    }
}
